package ui;


import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;

public class TextBar extends Composite implements KeyListener{
	private Text text;

	public TextBar(Composite parent, int style) {
		super(parent, SWT.NONE);
		addKeyListener(this);
		setLayout(new FormLayout());
		
		text = new Text(this, style);
		FormData fd_text = new FormData();
		fd_text.bottom = new FormAttachment(100, 3);
		fd_text.right = new FormAttachment(100, -8);
		fd_text.top = new FormAttachment(0, 10);
		fd_text.left = new FormAttachment(0, 8);
		text.setLayoutData(fd_text);
	}

	public void initail(Image backgound, int width, int height) {
		if (backgound != null) {
			setRegion(ui.global.GraphicsUtil.handleTransparenceRegion(backgound, width, height));
		}
		setSize(width, height);
		
	}
	
	public void setEditable(boolean editable) {
		text.setEditable(editable);
	}
	
	@Override
	public void setFont(Font font) {
		text.setFont(font);
	}
	
	@Override
	public void setBackground(Color color) {
		super.setBackground(color);
		text.setBackground(color);
	}
	
	public String getText() {
		return text.getText();
	}
	
	public void setText(String string) {
		text.setText(string);
	}
	
	public void setMessage(String string) {
		text.setMessage(string);
	}
	
	protected void execute() {
		
	}
	

	@Override
	public void keyPressed(KeyEvent e) {
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		if (e.keyCode == 13) {
			execute();
		}
	}

}
